--This is a support node, it doesn't give out XP, but rather items.
--The items can be required by other nodes and those will reward XP.

local col_box = {
   type = 'fixed',
   fixed = {{-.45, -.5, -.45, .5, .275, .5},
            {-.45, .275, 0, .5, .7, .5}, --Left, Bottom, Front, Right, Top, Back
            {.5, -.5, -.45, 1.45, 1.5, .5}}
   }

local storage_locker =
   'size[8,6]'..
   'textarea[2.25,.5;4.25,2.1;;Instructions;Place an item request in the left, and take your item out of the slot on the right.\nPlease be patient, it takes time to find the part you want.]' ..
   'list[current_name;src;.75,1;1,1;]'..
   'list[current_name;dst;6.25,1;1,1;]'..
   'list[current_player;main;0,3;8,3;]'

minetest.register_node('tasks:storage_locker_0', {
   description = 'Red Storage Locker',
   drawtype = 'mesh',
   mesh = 'tasks_storage_locker.obj',
   tiles = {'tasks_storage_locker_0.png'},
   groups = {breakable=1},
   light_source = 2,
   paramtype = 'light',
   paramtype2 = 'facedir',
   selection_box = col_box,
   collision_box = col_box,
   on_construct = function(pos)
      local meta = minetest.get_meta(pos)
      local inv = meta:get_inventory()
      inv:set_size('src', 1)
      inv:set_size('dst', 1)
      meta:set_string('infotext', 'Storage Locker')
      meta:set_string('formspec', storage_locker)
   end,
   allow_metadata_inventory_put = function(pos, listname, index, stack, player)
      if listname == 'src' then
         local item = string.sub(stack:get_name(), -3)
         if item == 'req' then
            return 1
         else
            return 0
         end
      else
         return 0
      end
   end,
   on_metadata_inventory_put = function(pos, listname, index, stack, player)
      local timer = minetest.get_node_timer(pos)
      timer:start(5)
   end,
   on_timer = function(pos)
      local meta = minetest.get_meta(pos)
      local inv = meta:get_inventory()
      local instack = inv:get_stack('src', 1)
      local inputstack = instack:get_name()
      local item = string.sub(inputstack, 0, -5)
      inv:set_stack('src', 1, '')
      inv:set_stack('dst', 1, item)
   end,
})
